﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace canyinguanlixitong
{
    public partial class frmaddspcs : Form
    {
        public frmaddspcs()
        {
            InitializeComponent();
        }

        private void frmaddspcs_Load(object sender, EventArgs e)
        {
            seargoods();
        }
        DataSet dl=new DataSet("Goods");
        string strconn="Data Source=.;Initial Catalog=Supermarket management system;Integrated Security=True";
        public void seargoods()
        {
            SqlConnection conn = new SqlConnection(strconn);
            if (dl.Tables["Goods"] != null)
            {
                dl.Tables["Goods"].Clear();
            }
            string sql = @"SELECT   [Commodity type].slLei, commodity.spID, commodity.spName, commodity.spJia
FROM      commodity INNER JOIN
                [Commodity type] ON commodity.spLei = [Commodity type].SlId";
            SqlDataAdapter ada = new SqlDataAdapter(sql, conn);
            ada.Fill(dl, "Goods");
            dataGridView1.DataSource = dl.Tables["Goods"];
        }
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
        public void add() {
            SqlConnection conn = new SqlConnection(strconn);
            conn.Open();
            int bianhao = Convert.ToInt32(this.textBox1.Text);
            string name = this.textBox2.Text;
            string money = this.textBox3.Text;
            int lei = Convert.ToInt32(this.textBox4.Text);
            string sql = "insert into commodity(spID,spName,spJia,spLei)values('"+bianhao+"','"+name+"','"+money+"','"+lei +"')";
            SqlCommand cmd = new SqlCommand(sql,conn);
            int result = cmd.ExecuteNonQuery();
            if (result == 1)
            {
                MessageBox.Show("新增成功");
               
            }
            else {
                MessageBox.Show("新增失败");
            }

            conn.Close();
        
        }
        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            add();
        }
    }
}
